#include "robber.h"

robber::robber(string filename, Arena* level) : creature(filename, level)
{

}

void robber::chase(creature* player)
{
	if(player->getX() > mXPosition)
	{
		if(map->IsEmpty(mXPosition + 20, mYPosition) == '.')
		{
			right();
		}
	}
	else if(player->getX() < mXPosition)
	{
		if(map->IsEmpty(mXPosition - 20, mYPosition) == '.')
		{
			left();
		}
	}
	
	if(player->getY() > mYPosition)
	{
		if(map->IsEmpty(mXPosition, mYPosition + 20) == '.')
		{
			down();
		}
	}
	else if(player->getY() < mYPosition)
	{
		if(map->IsEmpty(mXPosition, mXPosition - 20) == '.')
		{
			up();
		}
	}
}

void robber::spawn(creature* player)
{
	int randX = 0;
	int randY = 0;
	do
	{
		randX = rand() % 30+2;
		randY = rand() % 24+2;

		if(player->getX() / 20 == randX && player->getY() / 20 == randY)
			continue;

	}while( map->IsEmpty(randX*20, randY*20) != '.');

	mXPosition = (randX)*20;
	mYPosition = (randY)*20;
}

bool robber::CollidesWithPlayer(creature* player)
{
	if(player->getX() == mXPosition && player->getY() == mYPosition)
		return true;
	else
		return false;
}